﻿<?php
@require '../Controller/ConnectFB.php';
require '../Controller/Config.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<!DOCTYPE html>
<html>
    <head>
        <link rel="shortcut icon" href="../icon/favicon.ico"/>
        <link rel="stylesheet" href="../css/myStyle.css" type="text/css" />
        <script type="text/javascript" src="../js/jquery.fixedMenu.js"></script>
   <link rel="stylesheet" type="text/css" href="../css/fixedMenu_style2.css" />


   <link class="include" rel="stylesheet" type="text/css" href="../css/jquery.jqplot.min.css" />
    <!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../js/excanvas.js"></script><![endif]-->
    <script class="include" type="text/javascript" src="../js/jquery.min.js"></script>
    <script class="include" type="text/javascript" src="../js/jquery.jqplot.min.js"></script>
    <script class="include" type="text/javascript" src="../js/jqplot.canvasTextRenderer.min.js"></script>
    <script class="include" type="text/javascript" src="../js/jqplot.canvasAxisLabelRenderer.min.js"></script>
    <script class="include" type="text/javascript" src="../js/jqplot.canvasAxisTickRenderer.min.js"></script>
    <script class="include" type="text/javascript" src="../js/jqplot.categoryAxisRenderer.min.js"></script>
    <script type="text/javascript" src="../js/jqplot.barRenderer.min.js"></script>
    <script type="text/javascript" src="../js/jqplot.dateAxisRenderer.min.js"></script>
    <script type="text/javascript" src="../js/jqplot.highlighter.min.js"></script>
    <script type="text/javascript" src="../js/jqplot.enhancedLegendRenderer.min.js"></script>
        <style>
        .chart { height:400px; width:700px; }
    </style>

    </head>
<style>
body
{
        background-image:url('../images/bg.jpg');
        background-repeat:repeat-x;
        background-color:#f8e3b7;
 
}
</style>
    </head>
<body>

<table border="0" width="80%" height="650px" align="center" cellpadding="5" cellspacing="1" bgcolor="#404040">
  <tr height="30px">
    <td colspan="2" bgcolor="#ffffff">
        <div class="menu">
        <ul align="left">
            <table align="left" border="0">
                <tr>
                    <td>
                        <a href="../Interface/MenuHome.php">Home</a>
                    </td>
                </tr>
            </table>
            

            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuCreatePoll.php">Create Poll</a>
                    </td>
                </tr>
            </table>

            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuAnswer.php">Answer Poll</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../View/Compensation.php">Compensation</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../View/Statistics.php">Statistics</a>
                    </td>
                </tr>
            </table>
            
           <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuAbout.php">About</a>
                    </td>
                </tr>
            </table>
            
            <table align="left" border="0">
                <tr>
                    <td>
                <a href="../Interface/MenuContact.php">Contact</a>
                    </td>
                </tr>
            </table>
        </ul>
            
            <ul align="right"> 
            <?php if($fb_user){?>
               <table align="right" border="0" >
                   <tr>
                       <td>
                           <img width="25px" higth="25px"  src="https://graph.facebook.com///<?php echo $fb_user?>/picture">
                       </td>
                       <td>
                       <font color="white" size="2" align="left"><?php echo $_SESSION['strName'] ?></font>
                <a href="<?php echo $logoutUrl?>" >Logout</a>
                </table>
                <?php }else{?>
                <table align="right" border="0" >
                    <tr>
                        <td>
                    <a href="javascript:popup('<?php echo $loginUrl?>','',500,350);">Login with Facebook</a>
                        </td>
                       </tr>
                   </table>
                <?php } ?>
              </ul> 
    </div>
    </td>
  </tr>
  <tr>

    <td colspan="2" bgcolor="#ffffff" align="center" valign="top">

    <table border="0" width="100%" height="650px" align="center" cellpadding="5" cellspacing="1" bgcolor="#ffffff">
    <tr>
        <td bgcolor="#ffffff" align="left" valign="top" width="60%">

        <!--/////////////////////////////////โพลที่มีผู้เข้ามาตอบมากที่สุด/////////////////////////////////////////////-->
        <?php

//                    $q="select * from poll where poll.created_by = '1008'";
                    $q="SELECT DISTINCT\n".
                      "poll.poll_title,\n".
                      "COUNT(history.user_id_facebook)AS count\n".
                      "FROM\n".
                      "poll\n".
                      "INNER JOIN history ON history.poll_id = poll.poll_id\n".
                      "WHERE history.`status` = 'answer'\n".
                      "GROUP BY poll.poll_id limit 5";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        ?>
        <table width="100%" border="0" align="top">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>โพลที่มีผู้ตอบมากที่สุด</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ไม่มีการสร้างแบบสอบถาม</font>
                                </td>
                            </tr>
        </table>
                        <?php
                    }else{
                        $count =1;
                        ?>
                        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>โพลที่มีผู้ตอบมากที่สุด</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>ชื่อแบบสอบถาม</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จำนวนคนตอบ(คน)</b></font>
                            </td>
                        </tr>
                 <?php
                        while($rs=mysql_fetch_array($qr)){
                            $date = new DateTime($rs['created_date']);
//                            echo $rs['count'];
                            $people += $rs['count'];
                            $total += $rs['total'];
                        if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        }
                ?>
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>"  height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><?php echo $rs['poll_title']?></font>
                            </td>
                            <td>
                                <font><?php echo number_format($rs['count']) ?></font>
                            </td>
                        </tr>

                <?php
                        $count++;
                        }
                        ?>
                       </table>
                <?php
                    }
                ?>
        <!--////////////////////จำนวนแบบสอบถามในแต่ละเดือน//////////////////////////////////////-->
        <?php
        $month2[]=array();
        for($m2=1;$m2<=12;$m2++){
                $q2 = "SELECT
                        poll.poll_id,
                        poll.poll_title,
                        poll.poll_desc,
                        poll.compensation,
                        poll.created_by,
                        poll.created_date
                        FROM
                        poll
                        WHERE MONTH(poll.created_date) = ".$m2." AND YEAR(poll.created_date) = ".date('Y')." GROUP BY poll_id";
//        echo $q2."<br/>";
        $rs2 = mysql_query($q2) or die("Error SQL[ ".$q2." ] ".mysql_error());
        $rowCount2 = mysql_num_rows($rs2);
            $month2[$m2] = $rowCount2;
        }
//        print_r($month2);


                  $size2 = count($month2);

                  $j2=0;
        foreach ($month2 as $key2 => $value2){
          if($key2>0){
                      if($key2==1){$key2="มกราคม";}
                      else if($key2==2){$key2="กุมภาพันธ์";}
                      else if($key2==3){$key2="มีนาคม";}
                      else if($key2==4){$key2="เมษายน";}
                      else if($key2==5){$key2="พฤษภาคม";}
                      else if($key2==6){$key2="มิถุนายน";}
                      else if($key2==7){$key2="กรกฎาคม";}
                      else if($key2==8){$key2="สิงหาคม";}
                      else if($key2==9){$key2="กันยายน";}
                      else if($key2==10){$key2="ตุลาคม";}
                      else if($key2==11){$key2="พฤศจิกายน";}
                      else if($key2==12){$key2="ธันวาคม";}


                    /*$result = $result . '["' . $key . '",' . $value . ']';*/
                    $result2 = $result2 .'["'. $key2 . '",' . $value2.']';
                     if($j2 != $size2-2){
                      $result2 = $result2.',';
                         }
                         $j2++;
                         }
                   }
                     $result2 =  '['.$result2.']';

//                     echo  $result2; 
                      ?>
                <!--///////////////////////////////////จำนวนผู้ตอบคำถามในแต่ละเดือน///////////////////////////////////////////-->
                
                <?php
        $month[]=array();
        for($m=1;$m<=12;$m++){
                $q = "SELECT DISTINCT
                        history.history_id,
                        history.user_id_facebook,
                        history.first_name,
                        history.last_name,
                        history.poll_id,
                        history.`status`,
                        history.occupation_id,
                        history.province_id,
                        history.sex_id,
                        history.age_range_id,
                        history.log_date
                        FROM
                        history
                        WHERE MONTH(history.log_date) = ".$m." AND YEAR(history.log_date) = ".date('Y')." GROUP BY user_id_facebook";
//        echo $q."<br/>";
        $rs = mysql_query($q) or die("Error SQL[ ".$q." ] ".mysql_error());
        $rowCount = mysql_num_rows($rs);
            $month[$m] = $rowCount;
        }
        /*print_r($month);*/


                  $size = count($month);

                  $j=0;
        foreach ($month as $key => $value){
          if($key>0){
                      if($key==1){$key="มกราคม";}
                      else if($key==2){$key="กุมภาพันธ์";}
                      else if($key==3){$key="มีนาคม";}
                      else if($key==4){$key="เมษายน";}
                      else if($key==5){$key="พฤษภาคม";}
                      else if($key==6){$key="มิถุนายน";}
                      else if($key==7){$key="กรกฎาคม";}
                      else if($key==8){$key="สิงหาคม";}
                      else if($key==9){$key="กันยายน";}
                      else if($key==10){$key="ตุลาคม";}
                      else if($key==11){$key="พฤศจิกายน";}
                      else if($key==12){$key="ธันวาคม";}


                    /*$result = $result . '["' . $key . '",' . $value . ']';*/
                    $result = $result .'["'. $key . '",' . $value.']';
                     if($j != $size-2){
                      $result = $result.',';
                         }
                         $j++;
                         }
                   }
                     $result =  '['.$result.']';

//                     echo  $result; 
                      ?>
                        <div id="chart2" class="chart" style="margin-top:20px; margin-left:20px; width:600px; height:300px;"></div>
                        <br/>
                      <div id="chart1" class="chart" style="margin-top:20px; margin-left:20px; width:600px; height:300px;"></div>
                     
<script class="code" type="text/javascript">
$(document).ready(function(){

  var plot3 = $.jqplot('chart1', [<? echo $result; ?>], {
    title:  '<?  echo "จำนวนผู้ตอบคำถามในแต่ละเดือน"; ?>',

    animate: true,
            seriesDefault: {
                showMarker: true,
                pointLabels: { show: true }
            },grid: {
                drawBorder: true,
                drawGridlines: true,

                shadow: true
            },
    highlighter: {yvalues : 1 ,

    formatString:'<table class="jqplot-highlighter"><tr><td>เดือน:</td><td>%s</td></tr><tr><td>จำนวนผู้ตอบ:</td><td>%s</td></tr><tr><td></table>',
          show: true,
          sizeAdjust: 7.5
      }, seriesDefaults: { // applies to all rows
          renderer: $.jqplot.BarRenderer,
          lineWidth: 2,
          style: 'square',
          rendererOptions: { smooth: true }
      },
//              legend: {
//          renderer: $.jqplot.EnhancedLegendRenderer,
//          show: true,
//          showLabels: true,
//          fontSize: '11px',
//          fontFamily: ["Lucida Grande","Lucida Sans Unicode","Arial","Verdana","sans-serif"],
//          rendererOptions: {
//              seriesToggle: 'normal'
//          }},
//          series:[{'label': 'จำนวนผู้ตอบคำถามในแต่ละเดือน'}]
    /*series:[{renderer:$.jqplot.BarRenderer}],*/
    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
          angle: 10
        },

    },
    axes: {
      xaxis: {
        renderer: $.jqplot.CategoryAxisRenderer,
        tickOptions: {
          labelPosition: 'middle'
        }
      },
      yaxis: {
        autoscale:true,
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
          labelPosition: 'start'
        }
      }
    }
  });
});
</script>
  

<script class="code" type="text/javascript">
$(document).ready(function(){

  var plot3 = $.jqplot('chart2', [<? echo $result2; ?>], {
    title:  '<?  echo "จำนวนแบบสอบถามในแต่ละเดือน"; ?>',

    animate: true,
            seriesDefault: {
                showMarker: true,
                pointLabels: { show: true }
            },grid: {
                drawBorder: true,
                drawGridlines: true,

                shadow: true
            },
    highlighter: {yvalues : 1 ,

    formatString:'<table class="jqplot-highlighter"><tr><td>เดือน:</td><td>%s</td></tr><tr><td>จำนวนแบบสอบถาม:</td><td>%s</td></tr><tr><td></table>',
          show: true,
          sizeAdjust: 7.5
      }, seriesDefaults: { // applies to all rows
      renderer: $.jqplot.BarRenderer, 
          lineWidth: 2,
          style: 'square',
          rendererOptions: { smooth: true }
      },
    /*series:[{renderer:$.jqplot.BarRenderer}]*/
    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
          angle: 10
        },

    },
    axes: {
      xaxis: {
        renderer: $.jqplot.CategoryAxisRenderer,
        tickOptions: {
          labelPosition: 'middle'
        }
      },
      yaxis: {
        autoscale:true,
        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
        tickOptions: {
          labelPosition: 'start'
        }
      }
    }
  });
});
</script>




        </td>
        <td bgcolor="#ffffff" align="center" valign="top">
        <!--///////////////////////////////////อาชีพที่มีผู้เข้ามาตอบมากที่สุด///////////////////////////////////////////-->
        <?php

//                    $q="select * from poll where poll.created_by = '1008'";
                    $q="SELECT\n".
                        "m_occupation.occupation_name,\n".
                        "COUNT(history.user_id_facebook)AS count\n".
                        "FROM\n".
                        "history\n".
                        "INNER JOIN m_occupation ON history.occupation_id = m_occupation.occupation_id\n".
                        "GROUP BY m_occupation.occupation_name\n".
                        "ORDER BY count desc\n".
                        "LIMIT 5";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        ?>
        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>สายอาชีพผู้ตอบแบบสอบถาม<br/>5 อันดับแรก</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ท่านไม่เคยสร้างแบบสอบถาม</font>
                                </td>
                            </tr>
        </table>
                        <?php
                    }else{
                        $count =1;
                        ?>
                        <table width="100%" border="0" align="top">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>สายอาชีพผู้ตอบแบบสอบถาม<br/>5 อันดับแรก</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>อาชีพ</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จำนวนคนตอบ(คน)</b></font>
                            </td>
                        </tr>
                 <?php
                        while($rs=mysql_fetch_array($qr)){
                            $date = new DateTime($rs['created_date']);
//                            echo $rs['count'];
                            $people += $rs['count'];
                            $total += $rs['total'];
                        if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        }
                ?>
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>"  height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><?php echo $rs['occupation_name']?></font>
                            </td>
                            <td>
                                <font><?php echo number_format($rs['count']) ?></font>
                            </td>
                        </tr>

                <?php
                        $count++;
                        }
                        ?>
                        </table>
                         <!--///////////////////////////////////จังหวัดที่มีผู้เข้ามาตอบมากที่สุด///////////////////////////////////////////-->
        <?php

//                    $q="select * from poll where poll.created_by = '1008'";
                    $q="SELECT\n".
                        "m_province.province_name,\n".
                        "Count(history.user_id_facebook) AS count\n".
                        "FROM\n".
                        "history\n".
                        "INNER JOIN m_province ON m_province.province_id = history.province_id\n".
                        "GROUP BY m_province.province_name\n".
                        "ORDER BY count desc\n".
                        "LIMIT 5";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        ?>
        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>จังหวัดของผู้ตอบแบบสอบถาม<br/>5 อันดับแรก</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ท่านไม่เคยสร้างแบบสอบถาม</font>
                                </td>
                            </tr>
        </table>
                        <?php
                    }else{
                        $count =1;
                        ?>
                        <table width="100%" border="0" align="top">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>จังหวัดของผู้ตอบแบบสอบถาม<br/>5 อันดับแรก</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จังหวัด</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จำนวนคนตอบ(คน)</b></font>
                            </td>
                        </tr>
                 <?php
                        while($rs=mysql_fetch_array($qr)){
                            $date = new DateTime($rs['created_date']);
//                            echo $rs['count'];
                            $people += $rs['count'];
                            $total += $rs['total'];
                        if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        }
                ?>
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>"  height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><?php echo $rs['province_name']?></font>
                            </td>
                            <td>
                                <font><?php echo number_format($rs['count']) ?></font>
                            </td>
                        </tr>

                <?php
                        $count++;
                        }
                        ?>
                        <?php
                         }
                         ?>
                        </table>
                         <!--///////////////////////////////////เพศที่มีผู้เข้ามาตอบมากที่สุด///////////////////////////////////////////-->
        <?php

//                    $q="select * from poll where poll.created_by = '1008'";
                    $q="SELECT\n".
                        "m_sex.sex_thai,\n".
                        "Count(history.user_id_facebook) AS count\n".
                        "FROM\n".
                        "history\n".
                        "INNER JOIN m_sex ON history.sex_id = m_sex.sex_id\n".
                        "GROUP BY m_sex.sex_thai\n".
                        "ORDER BY count desc\n".
                        "LIMIT 5";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        ?>
        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>เพศของผู้ตอบแบบสอบถาม</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ท่านไม่เคยสร้างแบบสอบถาม</font>
                                </td>
                            </tr>
        </table>
                        <?php
                    }else{
                        $count =1;
                        ?>
                        <table width="100%" border="0" align="top">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>เพศของผู้ตอบแบบสอบถาม</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>เพศ</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จำนวนคนตอบ(คน)</b></font>
                            </td>
                        </tr>
                 <?php
                        while($rs=mysql_fetch_array($qr)){
                            $date = new DateTime($rs['created_date']);
//                            echo $rs['count'];
                            $people += $rs['count'];
                            $total += $rs['total'];
                        if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        }
                ?>
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>"  height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><?php echo $rs['sex_thai']?></font>
                            </td>
                            <td>
                                <font><?php echo number_format($rs['count']) ?></font>
                            </td>
                        </tr>
                        
                <?php
                        $count++;
                        }
                        ?>
                        <?php
                         }
                         ?>
                        </table>
                         <!--///////////////////////////////////ช่วงอายุที่มีผู้เข้ามาตอบมากที่สุด///////////////////////////////////////////-->
        <?php

//                    $q="select * from poll where poll.created_by = '1008'";
                    $q="SELECT\n".
                        "CONCAT(m_age_range.age_range_from,\" - \",m_age_range.age_range_to)AS age,\n".
                        "Count(history.user_id_facebook) AS count\n".
                        "FROM\n".
                        "history\n".
                        "INNER JOIN m_age_range ON m_age_range.age_range_id = history.age_range_id\n".
                        "GROUP BY m_age_range.age_range_from\n".
                        "ORDER BY count desc\n".
                        "LIMIT 5";
                    $qr=mysql_query($q);
                    $num_rows = @mysql_num_rows($qr);
//                    echo $q;
                    if($num_rows==0){
                        ?>
        <table width="100%" border="0" align="center">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>ช่วงอายุของผู้ตอบแบบสอบถาม 5 อันดับแรก</b></font>
                                </td>
                            </tr>
                            <tr>
                                <td align="center">
                                    <font size="4" align="left">ท่านไม่เคยสร้างแบบสอบถาม</font>
                                </td>
                            </tr>
        </table>
                        <?php
                    }else{
                        $count =1;
                        ?>
                        <table width="100%" border="0" align="top">
                            <tr valign="top" height="40px">
                                <td colspan="3" border="1" align="center" valign="middle" bgcolor="#e96c10">
                                    <font color="#ffffff" size="4" align="center"><b>ช่วงอายุของผู้ตอบแบบสอบถาม 5 อันดับแรก</b></font>
                                </td>
                            </tr>
                        <tr align="center" bgcolor="#ee974a" height="30px">
                            <td>
                                <font color="#ffffff"><b>ลำดับที่</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>ช่วงอายุ</b></font>
                            </td>
                            <td>
                                <font color="#ffffff"><b>จำนวนคนตอบ(คน)</b></font>
                            </td>
                        </tr>
                 <?php
                        while($rs=mysql_fetch_array($qr)){
                            $date = new DateTime($rs['created_date']);
//                            echo $rs['count'];
                            $people += $rs['count'];
                            $total += $rs['total'];
                        if($count%2==0){
                            $bgcolor = "#ffffff";
                        }else{
                            $bgcolor = "#f6d6a5";
                        }
                ?>
                        <tr align="center" bgcolor="<?php echo $bgcolor ?>"  height="25px">
                            <td>
                                <font><?php echo $count?></font>
                            </td>
                            <td>
                                <font><?php echo $rs['age']?></font>
                            </td>
                            <td>
                                <font><?php echo number_format($rs['count']) ?></font>
                            </td>
                        </tr>

                <?php
                        $count++;
                        }
                        ?>
                        <?php
                         }
                         ?>
                         <!--//////////////////////////////////////////////////////////////////////////////-->

                       </table>
                <?php
                    }
                ?>
        </td>
    </tr>
    </table>








    <!--<img border="0" src="../images/Coming-Soon-logo.gif" alt="" width="500" height="500">-->

          <?

        ?>


    </td>
  </tr>
</table>


</body>
</html>

